<?php

class Posts extends Extension
{
	protected $table = 'posts';
	
	public function latestPosts(array $fields, array $forums = array(), array $limit = array(5))
	{
		$this
			->fields($fields)
			->limit($limit)
			->order('last_post_time DESC', 'title ASC');
		
		$stmt = $this->execute();
		
		return $stmt->fetchAll();
	}
	
	public function forums($where)
	{
		$numArgs	= func_num_args();
		$args		= func_get_args();
		
		if (func_get_arg($numArgs - 1) === false)
		{
			$equals	= ' != ';
			$in		= ' NOT IN ';
			
			array_pop($args);
		}
		else
		{
			$equals	= ' = ';
			$in		= ' IN ';
		}
		
		if (func_num_args() == 1)
		{
			$this->where('forum_id' . $equals . $where);
		}
		else
		{
			$where = 'forum_id' . $in . '(' . implode(', ', $args) . ')';
			
			$this->where($where);
		}
		
		return $this;
	}
}

?>